import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'
const routes: Array<RouteRecordRaw> = [
  {
    path: '/detail',
    name: 'Detail',
    component: () => import(/* webpackChunkName: "home" */ '@/views/Detail.vue')
  },
  {
    path: '/home',
    name: 'Home',
    // 有时候我们想把某个路由下的所有组件都打包在同个异步块 (chunk) 中。只需要使用 命名 chunk
    component: () => import(/* webpackChunkName: "home" */ '@/views/Home.vue'),
    children: [
      {
        path: 'article',
        component: () => import('@/views/home/Article.vue')
      },
      {
        path: 'toDoList',
        component: () => import('@/views/home/ToDoList.vue')
      },{
        path: 'index',
        component: () => import('@/views/home/Index.vue')
      }
    ]
  },
  {
    path: '/',
    redirect: '/home/index',
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

// 路由守卫
router.beforeEach((to, from, next) => {
  console.log(to,from);
  
  next()
  // const isLogin = localStorage.ele_login ? true : false;
  // if (to.path == '/login') {
  //   next();
  // } else {
  //   // 是否在登录状态下
  //   isLogin ? next() : next('/login');
  // }
});


export default router
